home *** CD-ROM | disk | FTP | other *** search
/ Aminet 15 / Aminet 15 - Nov 1996.iso / Aminet / text / hyper / hsc_source.lha / source / hscprj / project.c < prev    next >
C/C++ Source or Header  |  1996-09-12  |  5KB  |  222 lines

  1. /*
  2.  * hscprj/project.c
  3.  *
  4.  * project managment routines for hsc
  5.  *
  6.  * Copyright (C) 1995,96  Thomas Aglassinger
  7.  *
  8.  * This program is free software; you can redistribute it and/or modify
  9.  * it under the terms of the GNU General Public License as published by
  10.  * the Free Software Foundation; either version 2 of the License, or
  11.  * (at your option) any later version.
  12.  *
  13.  * This program is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.  * GNU General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU General Public License
  19.  * along with this program; if not, write to the Free Software
  20.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  *
  22.  * updated: 12-Sep-1996
  23.  * created: 13-Apr-1996
  24.  */
  25.  
  26. #include <stdio.h>
  27. #include <stdarg.h>
  28. #include <string.h>
  29. #include <errno.h>
  30. #include <time.h>
  31.  
  32. #include "hsclib/ldebug.h"
  33. #include "hscprj/pdebug.h"
  34.  
  35. #include "ugly/utypes.h"
  36. #include "ugly/dllist.h"
  37. #include "ugly/expstr.h"
  38. #include "ugly/umemory.h"
  39. #include "ugly/infile.h"
  40. #include "ugly/ustring.h"
  41.  
  42. #include "hscprj/document.h"
  43. #include "hscprj/project.h"
  44.  
  45. /*
  46.  * new_project
  47.  */
  48. HSCPRJ *new_project(VOID)
  49. {
  50.     HSCPRJ *hp = (HSCPRJ *) umalloc(sizeof(HSCPRJ));
  51.  
  52.     if (hp)
  53.     {
  54.         memset(hp, 0, sizeof(HSCPRJ));
  55.         hp->documents = init_dllist(del_document);
  56.     }
  57.  
  58.     return (hp);
  59. }
  60.  
  61. /*
  62.  * del_project
  63.  */
  64. VOID del_project(HSCPRJ * hp)
  65. {
  66.     if (hp)
  67.     {
  68.         del_dllist(hp->documents);
  69.         del_document(hp->document);
  70.         ufree(hp);
  71.     }
  72. }
  73.  
  74. /*
  75.  * check_document_id
  76.  *
  77.  * append id to id_ref-list so it as checked when
  78.  * check_all_local_id_ref() is called
  79.  */
  80. int check_document_id(HSCPRJ * hp, STRPTR docname, STRPTR id)
  81. {
  82.     int err = ERR_CDI_OK;
  83.     HSCDOC *document = find_document(hp->documents, docname);
  84.  
  85.     DP(fprintf(stderr, DHP "  check id: `%s#%s'\n", docname, id));
  86.  
  87.     if (document)
  88.     {
  89.         HSCIDD *iddef = NULL;
  90.  
  91.         iddef = find_iddef(document, id);
  92.         if (!iddef)
  93.         {
  94.             DP(fprintf(stderr, DHP "    id unknown\n"));
  95.             err = ERR_CDI_NoID;
  96.         }
  97.         else
  98.         {
  99.             DP(fprintf(stderr, DHP "    id ok\n"));
  100.             err = ERR_CDI_OK;
  101.         }
  102.     }
  103.     else
  104.     {
  105.         DP(fprintf(stderr, DHP "    no file-entry in project\n",
  106.                    docname, id));
  107.         err = ERR_CDI_NoDocumentEntry;
  108.     }
  109.  
  110.     return (err);
  111. }
  112.  
  113. /*
  114.  * hsc_project_set_filename
  115.  *
  116.  * set project-filename (used by hsc_project_write_file())
  117.  */
  118. BOOL hsc_project_set_filename(HSCPRJ * hp, STRPTR new_prjname)
  119. {
  120.     BOOL ok = TRUE;
  121.     DP(fprintf(stderr, DHP "set project `%s'\n", new_prjname));
  122.  
  123.     if (hp->document->sourcename)
  124.     {
  125.         panic("project-name already set");
  126.     }
  127.  
  128.     hp->document->sourcename = strclone(new_prjname);
  129.  
  130.     return (ok);
  131. }
  132.  
  133. /*
  134.  * hsc_project_add_document
  135.  *
  136.  * add current document to project
  137.  */
  138. BOOL hsc_project_add_document(HSCPRJ * hp)
  139. {
  140.     BOOL ok = TRUE;
  141.  
  142.     app_dlnode(hp->documents, hp->document);
  143.     hp->document = NULL;
  144.  
  145.     return (ok);
  146. }
  147.  
  148. /*
  149.  * hsc_project_set_document
  150.  *
  151.  * Remove document from project's document list and
  152.  * create a new empty document with this name and
  153.  * make it the current document of the project.
  154.  * The new document is added to the project when the
  155.  * project-file is updated.
  156.  */
  157. BOOL hsc_project_set_document(HSCPRJ * hp, STRPTR new_docname)
  158. {
  159.     BOOL ok = TRUE;
  160.     DLNODE *nd = find_document_node(hp->documents, new_docname);
  161.     DP(fprintf(stderr, DHP "set document `%s'\n", new_docname));
  162.  
  163.     /* dettach document from project */
  164.     if (nd)
  165.     {
  166.         DP(fprintf(stderr, DHP "  remove old document `%s'\n",
  167.                    ((HSCDOC *) dln_data(nd))->docname));
  168.         del_dlnode(hp->documents, nd);
  169.     }
  170.     else
  171.     {
  172.         DP(fprintf(stderr, DHP "  new document `%s'\n", new_docname));
  173.     }
  174.  
  175.     /* remove current document */
  176.     if (hp->document)
  177.     {
  178.         DP(fprintf(stderr, DHP "  remove current document `%s'\n",
  179.                    hp->document->docname));
  180.         del_document(hp->document);
  181.     }
  182.  
  183.     hp->document = new_document(new_docname);
  184.  
  185.     return (ok);
  186. }
  187.  
  188. /*
  189.  * hsc_project_set_source
  190.  *
  191.  * set main source for project's current document
  192.  */
  193. BOOL hsc_project_set_source(HSCPRJ * hp, STRPTR new_sourcename)
  194. {
  195.     BOOL ok = TRUE;
  196.     DP(fprintf(stderr, DHP "set source `%s'\n", new_sourcename));
  197.  
  198.     if (!hp->document->sourcename)
  199.         hp->document->sourcename = strclone(new_sourcename);
  200.     else
  201.     {
  202.         panic("sourcename already set");
  203.         ok = FALSE;
  204.     }
  205.  
  206.     return (ok);
  207. }
  208.  
  209. /*
  210.  * hsc_project_add_include
  211.  *
  212.  * add include-file to project's current document
  213.  */
  214. BOOL hsc_project_add_include(HSCPRJ * hp, STRPTR new_includename)
  215. {
  216.     BOOL ok = TRUE;
  217.     DP(fprintf(stderr, DHP "add include `%s'\n", new_includename));
  218.     app_include(hp->document, new_includename);
  219.     return (ok);
  220. }
  221.  
  222.